<template>
  <div>
    <el-form class="main-content" ref="form" inline :model="form" label-width="120px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="姓名:" prop="userName" label-width="80px">
            <el-input v-model="form.userName" placeholder="请输入姓名"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="人员编号:" prop="uid" label-width="80px">
            <el-input v-model="form.uid" placeholder="请输入人员编号"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="专兼职:" prop="isFullTime" label-width="80px">
            <el-select style="width: 100%" v-model="form.isFullTime">
              <el-option label="专职" value="1"></el-option>
              <el-option label="兼职" value="2"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="small" @click="getPersonnel">搜索</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="small" @click="getPersonnel">批量导出</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="danger" icon="el-icon-delete" size="small" @click="handleReset">清空</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="main-content personnel-table">
      <el-table border :data="tableData" style="width: 100%" max-height="400">
        <el-table-column prop="uid" label="人员编号" align="center" />
        <el-table-column prop="userName" label="姓名" align="center" />
        <el-table-column prop="sex" label="性别" align="center" />
        <el-table-column prop="phone" label="联系手机" align="center" />
        <el-table-column prop="branchPersonnel" label="分公司人员" align="center" />
        <el-table-column prop="regionalAddress" label="区划地址" align="center" />
        <el-table-column prop="isFullTime" label="专兼职" align="center" />
        <el-table-column prop="idNo" label="身份证号码" align="center" />
        <el-table-column prop="mark" label="备注" align="center" />
        <el-table-column label="操作" width="120">
          <template slot-scope="scope">
            <el-button @click.native.prevent="handleJump(scope.row)" type="text" size="small">编辑</el-button>
            <el-button @click.native.prevent="handleDeletePre(scope.row)" type="text" class="btn-delete"
              size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination background layout="prev, pager, next" :page-size="pageInfo.pageSize" :total="pageInfo.total"
        @current-change="handleChangeCurrent" />
    </div>
    <el-dialog title="提示" :visible.sync="visible" width="30%">
      <span>确认删除单号为{{ currentInfo.did }}的登记记录吗?</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取 消</el-button>
        <el-button type="primary" @click="visible = false">确 定</el-button>
      </span>

      <template #footer>
        <span class="dialog-footer">
          <el-button @click="visible = false">取消</el-button>
          <el-button type="primary" @click="handleDelete"> 确定 </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { getPersonnel, delPersonnel } from "../../api/personnel";
export default {
  name: "HrQuery",
  data() {
    return {
      form: {
        userName: null,
        id: null,
        personnelNature: null,
        isFullTime: null,
        regionalAddress: null,
        phone: null,
        expire: null,
      },
      tableData: [],
      pageInfo: {
        current: 1,
        pageSize: 10,
      },
      visible: false,
      currentInfo: {},
    };
  },
  created() {
    this.getPersonnel();
  },
  methods: {
    async getPersonnel() {
      const { current, pageSize } = this.pageInfo;
      const res = await getPersonnel({ ...this.form, current, pageSize });
      const { data, pageInfo } = res?.data;
      this.tableData = data;
      this.pageInfo = pageInfo;
    },

    handleJump(row) {
      const { uid, id } = row;
      this.$router.push(`/hr/qualification/detail?uid=${uid}&pid=${id}`);
    },

    handleChangeCurrent(index) {
      this.pageInfo.current = index;
      this.getPersonnel();
    },
    handleReset() {
      this.$refs["form"].resetFields();
      this.getPersonnel();
    },
    handleDeletePre(info) {
      this.visible = true;
      this.currentInfo = info;
    },
    async handleDelete() {
      if (!this.currentInfo.id) {
        this.$message({
          type: "warning",
          message: "无效操作",
        });
      }
      const res = await delPersonnel({ id: this.currentInfo.id });
      if (res?.data?.code === 0) {
        this.visible = false;
        this.$message({
          type: "success",
          message: "删除成功",
        });
        this.getPersonnel();
      }
    },
  },
};
</script>

<style lang="less" scoped>
.personnel-table {
  margin-top: 20px;

  /deep/ .el-pagination {
    margin-top: 20px;
    text-align: center;
  }
}
</style>
